package com.flying.invest.base.service;

import com.flying.common.annotation.DaoCreate;
import com.flying.common.annotation.DaoQuery;
import com.flying.common.annotation.DaoRemove;
import com.flying.common.util.Codes;
import com.flying.common.util.DateUtils;
import com.flying.common.util.DateUtils.Weekday;
import com.flying.framework.annotation.MethodInfo;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.Service;
import com.flying.framework.model.ActionResult;
import com.flying.framework.model.ModelFactory;
import com.flying.framework.model.QueryResult;
import com.flying.framework.service.AbstractService;
import com.flying.invest.base.model.Holiday;

@Service(value="HolidayService", desc="")
public class HolidayService extends AbstractService{
        
	@MethodInfo("新增")
	@DaoCreate(entity=Holiday.ENTITY_NAME)
	public Holiday create(
		
			@Param(value=Holiday.CURRENCY, required=true,	desc="币种") String currency,
			@Param(value=Holiday.HOLIDAY, required=true,	desc="假期") String holiday,
			@Param(value=Holiday.REMARKS, required=false,	desc="说明") String remarks
		
		) {
		
		return null;
	}
	
	public ActionResult initByYear(
			@Param(value=Holiday.CURRENCY, required=true,	desc="币种") String currency,
			@Param("year") int year) {
		for(int i=1; i<=365; i++) {
			var date = DateUtils.getDate(year, i);
			Weekday wd = DateUtils.getWeekDay(date);
			if(wd == Weekday.SAT || wd == Weekday.SUN) {
				String holiday = DateUtils.formatDate(date, "yyyy-MM-dd");
				this.create(currency, holiday, "周末" + wd);
			}
		}
		return ModelFactory.create(ActionResult.class, Codes.CODE, Codes.SUCCESS);
	}

	@MethodInfo("删除")
	@DaoRemove(entity=Holiday.ENTITY_NAME)
	public ActionResult remove(
			@Param(value=Holiday.CURRENCY, required=true,	desc="币种") String currency,
			@Param(value=Holiday.HOLIDAY, required=true,	desc="假期") String holiday
		) {
		
		return null;
	}

	@MethodInfo("搜索")
	@DaoQuery(entity=Holiday.ENTITY_NAME, pageable=true, modelClass=Holiday.class)
	public QueryResult<Holiday> findAll(
			@Param(value=Codes.PAGE_NUM, 	required=false, desc="分页页号，默认0") int page,
			@Param(value=Codes.PAGE_SIZE, 	required=false, desc="分页大小，默认10") int rows) {
		return null;
	}

	@MethodInfo("查询")
	@DaoQuery(entity=Holiday.ENTITY_NAME, single=true, throwsNotFoundException=true )
	public Holiday findById(
		
			@Param(value=Holiday.CURRENCY, required=true,	desc="币种") String currency,
			@Param(value=Holiday.HOLIDAY, required=true,	desc="假期") String holiday
		) {
		return null;
	}

}